
var name = "#writeFormLayer";
var hideWrite = true;

$(document).ready(function(){
	
});  


function showLoading(){
	$("#loadingbar").fadeIn(300);
}
function hideLoading(){
	$("#loadingbar").fadeOut(300);
}
function getResult(keyObj){
	$("#firstContent").fadeOut(300);
	showLoading();
	$.ajax({ 
		  type: "POST", 
		  url: "resultdaum.jsp", 
		  data: "&q="+encodeURI($(keyObj).attr('keyword')), 
		  success: function(data){
			var cur_daum_data = data;
		    
		    
		    $.ajax({ 
				  type: "POST", 
				  url: "resultnaver.jsp", 
				  data: "&q="+encodeURI($(keyObj).attr('keyword')), 
				  success: function(ndata){
				    $("#resultLayerNaver").html(ndata);
				    $("#resultLayerDaum").html(cur_daum_data);
				    hideLoading();
				  } 
				});
		  } 
		});
	
}
function hideResult(target){
	if(target=='blogSearch' && $("#blogSearchContent").css('display')!='none')
		$("#blogSearchContent").hide("slide", { direction: "up" }, 300);
	if(target=='imgSearch' && $("#imgSearchContent").css('display')!='none')
		$("#imgSearchContent").hide("slide", { direction: "up" }, 300);
	if(target=='vidSearch' && $("#vidSearchContent").css('display')!='none')
		$("#vidSearchContent").hide("slide", { direction: "up" }, 300);
	if(target=='nblogSearch' && $("#nblogSearchContent").css('display')!='none')
		$("#nblogSearchContent").hide("slide", { direction: "up" }, 300);
	if(target=='nimgSearch' && $("#nimgSearchContent").css('display')!='none')
		$("#nimgSearchContent").hide("slide", { direction: "up" }, 300);
	if(target=='nvidSearch' && $("#nvidSearchContent").css('display')!='none')
		$("#nvidSearchContent").hide("slide", { direction: "up" }, 300);
	if(target=='newsSearch' && $("#newsSearchContent").css('display')!='none')
		$("#newsSearchContent").hide("slide", { direction: "up" }, 300);
}
function showResult(target){
	if(target=='blogSearch' && $("#blogSearchContent").css('display')!='block')
		$("#blogSearchContent").show("slide", { direction: "up" }, 300);
	if(target=='imgSearch' && $("#imgSearchContent").css('display')!='block')
		$("#imgSearchContent").show("slide", { direction: "up" }, 300);
	if(target=='vidSearch' && $("#vidSearchContent").css('display')!='block')
		$("#vidSearchContent").show("slide", { direction: "up" }, 300);
	if(target=='nblogSearch' && $("#nblogSearchContent").css('display')!='block')
		$("#nblogSearchContent").show("slide", { direction: "up" }, 300);
	if(target=='nimgSearch' && $("#nimgSearchContent").css('display')!='block')
		$("#nimgSearchContent").show("slide", { direction: "up" }, 300);
	if(target=='nvidSearch' && $("#nvidSearchContent").css('display')!='block')
		$("#nvidSearchContent").show("slide", { direction: "up" }, 300);
	if(target=='newsSearch' && $("#newsSearchContent").css('display')!='block')
		$("#newsSearchContent").show("slide", { direction: "up" }, 300);
}

function closeVideoLayer(){
	$("#videoPlayerLayer").html('');
	$("#videoPlayerTitle").html('');
	$("#videoPlayerBg").hide("slide", { direction: "up" }, 300);
}

function showVideo(obj){
	$("#videoPlayerBg").css("top",$(obj).offset().top);
	$("#videoPlayerTitle").html($(obj).attr('title'));
	$("#videoPlayerBg").show("slide", { direction: "up" }, 300);
	swfobject.embedSWF($(obj).attr('url'),
			"videoPlayerLayer","460","400","9.0.0",
			false,
			null,
			{wmode:"transparent",allowScriptAccess:"always"},
			{id:"videoPlayer"});
}


function tryPost(){

	$.ajax({
		type: "POST", 
		  url: "checkSession.jsp", 
		  success: function(data){
			if($.trim(data)=="NOT"){
				alert('블로그 API사용 정보가 존재하지 않습니다.\r\n입력 후 다시 시도해주세요.');
				$("#setAPILayer").show("slide",{ direction: "up" }, 300);
			}else{
				getNSetCategory();
				toggleWriteForm();
			}
		}
	});
	
}

function toggleWriteForm(){
	if(hideWrite){
		$("#writeFormLayer").animate({
			height: '400px'
			},
			300,
			'easeInOutCirc',
			function(){
				$("#writeFormLayer").css("overflow-y","visible");
			});
		hideWrite = false;
	}else{
		$("#writeFormLayer").animate({
			height: 0
			},
			300,
			"easeInOutCirc",
			function(){
				$("#writeFormLayer").css("overflow-y","hidden");
			});
		hideWrite = true;
	}
}

function endSession(){
	$.ajax({
		type: "POST", 
		  url: "endSession.jsp", 
		  success: function(data){
			if($.trim(data)=="END"){
				alert('정상처리되었습니다.');
			}
		}
	});
}

function getNSetCategory(){
	$.ajax({
		type: "POST", 
		  url: "getCategoryBlog.jsp", 
		  success: function(data){
			$("#tx_article_category").html(data);
		}
	});
}

function saveSession(){
	$.ajax({
		type: "POST", 
		data : "blogtype="+$("#blogType").val()+"&userid="+$("#userid").val()+"&userpw="+$("#userpw").val()+"&blogapiaddress="+$("#blogapiaddress").val()+"&blogapiid="+$("#blogapiid").val(),
		  url: "setSession.jsp", 
		  success: function(data){
			if($.trim(data)=="SUCCESS"){
				//카테고리 목록 가져오기
				getNSetCategory();
				$("#setAPILayer").hide("slide",{ direction: "up" }, 300);
				toggleWriteForm();
			}
		}
	});
}

function closeSetAPILayer(){
	$("#setAPILayer").hide("slide",{ direction: "up" }, 300);
}